//
//  FPHomeModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/2/12.
//

#import "FPHomeModel.h"

@implementation FPHomeDataModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
}
+ (void)getJumpDataSuccess:(void (^)(NSInteger, NSString * _Nonnull, FPHomeDataModel * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:HOME_PAGE_DATA_JUMP_URL] parameters:@{} type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        FPHomeDataModel *model = [[FPHomeDataModel alloc] initWithDictionary:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
//        NSString *dataInfo = [object objectForKey:@"data"];
        
        if (success) {
            
            success(httpCode , message , model);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


+ (void)getHomePageRateDataDisplaySuccess:(void (^)(NSInteger, NSString * _Nonnull, NSString * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:HOME_PAGE_DATA_DISPLAY_URL] parameters:@{} type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
//        FPHomeDataModel *model = [[FPHomeDataModel alloc] initWithDictionary:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        NSString *dataInfo = [object objectForKey:@"data"];
        
        if (success) {
            
            success(httpCode , message , dataInfo);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}

@end






@implementation FPHomeModel

+ (void)getHomePageInfoSuccess:(void (^)(NSInteger, NSString * _Nonnull, FPHomeModel * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:HOME_PAGE_URL] parameters:@{} type:HttpRequestTypeGet success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        NSDictionary *data = [object objectForKey:@"data"];
//        FPHomeModel *model = [[FPHomeModel alloc] initWithDictionary:data error:&error];
        FPHomeModel *model = [[FPHomeModel alloc] init];
        
        id totalCreditValue = [data objectForKey:@"totalCredit"];
        if ([totalCreditValue isKindOfClass:[NSNumber class]]) {
            model.totalCredit = [totalCreditValue stringValue];
        } else if ([totalCreditValue isKindOfClass:[NSString class]]) {
            model.totalCredit = totalCreditValue;
        } else {
            model.totalCredit = @"";
        }
        
        id dayCreditValue = [data objectForKey:@"dayCredit"];
        if ([dayCreditValue isKindOfClass:[NSNumber class]]) {
            model.dayCredit = [dayCreditValue stringValue];
        } else if ([dayCreditValue isKindOfClass:[NSString class]]) {
            model.dayCredit = dayCreditValue;
        } else {
            model.dayCredit = @"";
        }
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , model);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)getFeaturedNameSuccess:(void (^)(NSInteger, NSString * _Nonnull, NSString * _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:FEATURE_NAME_URL] parameters:@{} type:HttpRequestTypeGet success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        NSString *featureName = [object objectForKey:@"data"];
        
        if (success) {
            
            success(httpCode , message , featureName);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}



@end
